/*
 * Project: Simple Java Ray Tracer
 * By: Sander Langhorst
 * This project is based on the Processing library (http://processing.org)
 *
 */

package javaraytracer;

import java.util.*;
import processing.core.*;

//PENDING:add function/property description
/**
 *
 * @author Sander
 */
public class JavaRayTracer extends PApplet
{
	public static JavaRayTracer instance;
	public static int maxReflectionDepth = 10;
	public static ArrayList scene;
	public static int width = 1280;
	public static int height = 1024;
	public static int quality = 15;
	public static float qualityRatio = 0.5f;
	public static int softshadowIts = 20;
	public static Vec3 globalAmbient = new Vec3(0.1, 0.1, 0.1);

	public Tracer tracer;
	public Thread renderThread;
	public Camera cam;

	private static Scene loadme;
	private int time = 0;

	public PImage imageSource;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        PApplet.main( new String[]{"javaraytracer.JavaRayTracer"} );

    }

	@Override
    public void setup()
    {
		instance = this;
		//settings
		size(width, height, P2D);
		background(127, 127, 255);

		//load scene
		cam = new Camera();
		scene = new ArrayList();

		loadme = new Scene();
		scene = loadme.getObjects();

		imageSource = createImage(width, height, RGB);
		imageSource.loadPixels();

		tracer = new Tracer();
		renderThread = new Thread(tracer);
		//render();
		renderThread.start();
		renderThread.setPriority(Thread.MAX_PRIORITY);
		time = millis();
		
    }

	@Override
	public void draw()
	{
		background(50, 60, 170);
		imageSource.updatePixels();
		image(imageSource, 0, 0);
	}

	@Override
	public void mousePressed()
	{
		println("X: " + mouseX + ", Y: " + mouseY);
	}
	
	public void printTime()
	{
		println( "time past: " + (millis() - time) / 1000.0 + " seconds");
	}

}
